package com.czh.gzskzn.shenke3.Activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.czh.gzskzn.shenke3.Activity.UtilServer.WanZhi;
import com.czh.gzskzn.shenke3.R;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.Call;
import okhttp3.Response;

public class YeJianActivity extends AppCompatActivity {

    private ImageView bake;
    private TextView fason;
    private EditText shuru;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yijian_activity);

        intiView();
        VieDianJi();
    }
    private void VieDianJi() {
        bake.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        fason.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String yiJian = shuru.getText().toString();

                if (yiJian.equals("")) {
                    Toast.makeText(YeJianActivity.this, "请输入内容", Toast.LENGTH_SHORT).show();

                } else {

                    OkGo.post(WanZhi.BAIDU)
                            .tag(this)
                            .upString(yiJian)
                            .execute(new StringCallback() {
                                @Override
                                public void onSuccess(String s, Call call, Response response) {

                                    try {
                                        JSONObject jsonod = new JSONObject(s);
                                        Toast.makeText(YeJianActivity.this,s,Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }


                                }

                                @Override
                                public void upProgress(long currentSize, long totalSize, float progress, long networkSpeed) {

                                }
                            });

                }
            }
        });

    }

    private void intiView() {

        fason = (TextView) findViewById(R.id.right_btn);
        bake = (ImageView) findViewById(R.id.left_btn);
        shuru = (EditText) findViewById(R.id.feedback_content_edit);

    }
}
